package com.tarena.vehicle.management.controller;

import com.tarena.vehicle.common.pojo.vo.PageData;
import com.tarena.vehicle.common.web.JsonResult;
import com.tarena.vehicle.management.pojo.param.VehicleInsuranceAddNewParam;
import com.tarena.vehicle.management.pojo.param.VehicleInsuranceUpdateParam;
import com.tarena.vehicle.management.pojo.query.VehicleInsuranceQuery;
import com.tarena.vehicle.management.pojo.vo.VehicleInsuranceListItemVO;
import com.tarena.vehicle.management.pojo.vo.VehicleInsuranceStrandVO;
import com.tarena.vehicle.management.service.IVehicleInsuranceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/VehicleInsurance")
@Api(tags = "车辆保险信息管理")
public class VehicleInsuranceController {

    @Autowired
    private IVehicleInsuranceService vehicleInsuranceService;
    @ApiOperation("新增车辆保险信息")
    @PostMapping("/add-new")
    public JsonResult addNew(VehicleInsuranceAddNewParam vehicleInsuranceAddNewParam){
        vehicleInsuranceService.addNew(vehicleInsuranceAddNewParam);
        return JsonResult.ok("新增成功");
    }

    @ApiOperation("根据条件分页查询车辆保险信息")
    @GetMapping("/get-vehicle-insurance-all")
    public JsonResult<PageData<VehicleInsuranceListItemVO>> getVehicleInsuranceAll(Integer pageNum,Integer pageSize,
        VehicleInsuranceQuery vehicleInsuranceQuery){
        PageData<VehicleInsuranceListItemVO> vo=vehicleInsuranceService.getVehicleInsuranceAll(pageNum,pageSize,vehicleInsuranceQuery);
        return JsonResult.ok(vo);
    }
    @ApiOperation("根据ID查询车辆保险信息")
    @GetMapping("/get-vehicle-insurance/{id}")
    public JsonResult<VehicleInsuranceStrandVO> getVehicleInsuranceById(@PathVariable Integer id){
        VehicleInsuranceStrandVO vo=vehicleInsuranceService.getVehicleInsuranceById(id);
        return JsonResult.ok(vo);
    }

    @ApiOperation("修改车辆保险状态为未到期")
    @GetMapping("/update-vehicle-insurance-undue/{id}")
    public JsonResult updateVehicleInsuranceUndueStatusById(@PathVariable Integer id){
        vehicleInsuranceService.updateVehicleInsuranceUndueStatusById(id);
        return JsonResult.ok("修改成功");
    }

    @ApiOperation("修改车辆保险状态为已到期")
    @GetMapping("/update-vehicle-insurance-expire/{id}")
    public JsonResult updateVehicleInsuranceExpireStatusById(@PathVariable Integer id){
        vehicleInsuranceService.updateVehicleInsuranceExpireStatusById(id);
        return JsonResult.ok("修改成功");
    }

    @ApiOperation("修改车辆保险信息")
    @PostMapping("/update-vehicle-insurance")
    public JsonResult updateVehicleInsurance(VehicleInsuranceUpdateParam vehicleInsuranceUpdateParam){
        vehicleInsuranceService.updateVehicleInsurance(vehicleInsuranceUpdateParam);
        return JsonResult.ok("修改成功");
    }

    @ApiOperation("根据ID删除车辆信息")
    @GetMapping("/delete-vehicle-insurance/{id}")
    public JsonResult deleteVehicleInsuranceById(@PathVariable Integer id){
        vehicleInsuranceService.deleteVehicleInsuranceById(id);
        return JsonResult.ok("删除成功");
    }

}
